package com.yellowpage.ca.service;

import java.util.List;
import java.util.Map;

import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

import com.yellowpage.white.common.Constants;
import com.yellowpage.white.common.PageRender;
import com.yellowpage.white.dao.QueryAssistantSQL;
import com.yellowpage.white.service.BaseServiceImpl;

import com.yellowpage.ca.data.FuncModule;
import com.yellowpage.ca.dao.FuncModuleDao;

public class FuncModuleServiceImpl extends BaseServiceImpl implements FuncModuleService {
	  private FuncModuleDao funcModuleDao;
	
	  public void setFuncModuleDao(FuncModuleDao funcModuleDao) {
		  this.funcModuleDao = funcModuleDao;
	  }
	
	
	  /* white generate Method */ 
	  public FuncModule getFuncModule(Long id){
	      return funcModuleDao.get(id);
	  }
	  
    public List<FuncModule> getAllFuncModule(){
        return funcModuleDao.getAll();
    }
    
    public List<Map> queryFuncModuleByPage(Map queryMap, PageRender pageRender) {		
        
		QueryAssistantSQL sqlAssistant = baseDao.newQueryAssistantSQL(
				"SELECT a.FUNC_MODULE_ID , a.LEVEL_CODE , a.NAME , a.STATUS,  " +
				"       (select display_name from CA_USER where user_id = a.last_update_user) as last_update_user, " +
			    "       date_format(a.last_update_time,'%Y-%m-%d %T') as last_update_time, " +
			    "       (select display_name from CA_USER where user_id = a.create_user) as create_user," +
			    "       date_format(a.create_time,'%Y-%m-%d %T') as create_time " +
						"   FROM CA_FUNC_MODULE a WHERE 1=1 ")
				    			.addCondition(" and LEVEL_CODE like :levelCode ")
							    .addCondition(" and NAME like :name ")							    			
							    ; 	

		List<Map> resultList = sqlAssistant.queryByPage(
				baseDao.getConnection(), queryMap, pageRender);

		return resultList;
	}
    
    
    public void saveFuncModule(FuncModule funcModule){
        funcModuleDao.save(funcModule);
    }
    
	  public void updateFuncModule(FuncModule funcModule){
	      funcModuleDao.update(funcModule);
	  }
	  
	  public void delete(List deleteList){
	      funcModuleDao.remove(deleteList);
	  } 
	
}	